/**
 * Created by AllanXu on 01/03/2016.
 */
define(function (require) {
	var Vue = require('vue'),
        Config = require('config'),
		_ = require('ajax'),
		utilities = require('utilities');

	var id = utilities.getParameterByName('id');
    var AuthDialog = require('auth_dialog');
    var authDialog = new AuthDialog();

	var app = new Vue({
		el: '#room',
		data: {
            str: '',
            list: [],
            renderObj: {}
		},
		methods:{
			init: function () {
                utilities.refreshUserInfo(function (data) {
                    app.renderObj = data;
                });
                _(Config.DICTIONARY +'?parentId='+1054, {}, function(data) {
                    console.log(data);
                    app.list = data.obj['1054'];
                });
			},
            isChecked: function (item) {
                return !!item.checked;
            },
            pick: function (listName, i) {
                for (var key in app[listName]) {
                    app.$set(listName + '[' + key + '].checked', false);
                }
                app.$set(listName + '[' + i + '].checked', !app[listName][i].checked);
            },
            save:function () {
			    if(app.renderObj.member.sfrz==0){
                    authDialog.show();
                    return;
                }
                var hkdd='';
                if(utilities.getCheckedStr(app.list)==''){
                    alert("请选择会客地点！");
                    return;
                }
                hkdd=utilities.getCheckedStr(app.list);

                _(Config.SERVICE.MATES.VERIFY+'?id=' + app.renderObj.member.id, {}, function(data) {
                    if(data.errmsg.indexOf("择偶") > 0 ){
                        // 择偶条件没有完善跳转到择偶条件
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中完善择偶条件。")){
                            location.href = 'uc_mate_condition.html';
                        }
                    }else if(data.errmsg.indexOf("基本信息") > 0){
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中完善个人资料。")){
                            location.href = 'uc_profile.html';
                        }
                    }else if(data.errmsg.indexOf("形象照") > 0){
                        if(confirm("为更好地为您提供服务，请在“个人编辑”中上传形象照。")){
                            location.href = 'uc_basicInfo.html';
                        }
                    }else{
                        _(Config.SERVICE.USERCENTER.ACCOUNT_ROOM, {
                            'room.basic.id': sessionStorage.id,
                            'room.hkdd.id': hkdd,
                            'room.content': app.str
                        }, function(data) {
                            if(data.code == 200 && data.type === 'SUCCESS'){
                                alert('提交成功！');
                                utilities.refreshUserInfo(function (data) {
                                    history.back();
                                });
                            }else{
                                alert('您已经提交过申请了，请耐心等待我们会联系您的！');
                            }
                        });
                    }
                });
            }
		}
	});
	app.init();
});
